package com.example.taobao

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.Editable
import android.text.SpannableStringBuilder
import kotlinx.android.synthetic.main.newaddress.*
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request
import java.lang.Exception
import java.net.URLEncoder
import kotlin.concurrent.thread

class Alteraddress : AppCompatActivity() {
    var meg:ArrayList<String> = ArrayList<String>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_alteraddress)
        val intent = Intent()
        var bundle=this.intent.extras
        meg = ArrayList<String>(bundle?.getStringArrayList("message"))
        initdata()
        btn_save.setOnClickListener {
            thread {
                try {
                    val client = OkHttpClient()
                    val requestBody = FormBody.Builder()
                        .add("oldname", URLEncoder.encode(meg[0], "utf-8"))
                        .add("name", URLEncoder.encode(et_shouhuoren.text.toString(), "utf-8"))
                        .add(
                            "phonenumber",
                            URLEncoder.encode(et_Mobile.text.toString(), "utf-8")
                        )
                        .add("suozaidiqu", URLEncoder.encode(tv_city1.text.toString(), "utf-8"))
                        .add(
                            "xiangxidiz",
                            URLEncoder.encode(et_xiangxidizhi.text.toString(), "utf-8")
                        )
                        .add("username", URLEncoder.encode("何俊", "utf-8"))
                        .build()
                    val request = Request.Builder()
                        .url("http://192.168.43.140:8080/aaa_war_exploded/alter.jsp")
                        .post(requestBody)
                        .build()
                    val respone = client.newCall(request).execute()
                    val responeData = respone.body?.string()
                } catch (e: Exception) {
                    e.printStackTrace()
                }
                finish()
            }
        }
    }
    fun initdata()
    {
        val editable: Editable = SpannableStringBuilder(meg[0])
        et_shouhuoren.text = editable
        val editable1: Editable = SpannableStringBuilder(meg[1])
        et_Mobile.text = editable1
        val editable2: Editable = SpannableStringBuilder(meg[2])
        tv_city1.text = editable2
        val editable3: Editable = SpannableStringBuilder(meg[3])
        et_xiangxidizhi.text = editable3
    }
}